import logging
from typing import Dict, Any
from datetime import datetime

class MonitoringDashboard:
    """监控面板"""
    
    def __init__(self):
        self.metrics = {
            'processed_papers': 0,
            'failed_citations': 0,
            'emergency_mode_activations': 0,
            'start_time': datetime.now()
        }
        self.logger = logging.getLogger(__name__)

    def update(self, metric: str, value: Any = 1, increment: bool = True):
        """更新指标"""
        try:
            if increment:
                self.metrics[metric] = self.metrics.get(metric, 0) + value
            else:
                self.metrics[metric] = value
        except Exception as e:
            self.logger.error(f"指标更新失败: {str(e)}")

    def get_stats(self) -> Dict[str, Any]:
        """获取统计信息"""
        stats = self.metrics.copy()
        stats['uptime'] = (datetime.now() - stats['start_time']).seconds
        return stats

    def show(self):
        """显示监控面板"""
        stats = self.get_stats()
        print("\n=== 系统监控 ===")
        for k, v in stats.items():
            print(f"{k}: {v}")
        print("===============\n")
